﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Gladkikh.Sims2.Combiner.Database
{
    public class Sims2Addon
    {
       public string DisplayName, Name, Exe, ExePath, RegMask;
       public bool Enabled;

       public bool IsOk
       {
           get
           {
               return System.IO.File.Exists(ExePath) && Enabled;
        
           }
       }


        string getFolder(string exePath)
        {
            string folderPath = "";
            if (exePath != null && exePath != "")
            {
                folderPath = Path.GetDirectoryName(exePath);
                folderPath = Path.GetDirectoryName(folderPath);
            }
            return folderPath;
        }

        string getPath(string path)
        {
            //string s = Path.GetExtension(path);
            if (Path.GetExtension(ExePath) == ".exe")
                return path.Replace(@"\", @"\\");
            else
                return path.Replace(@"\", @"\\") + @"\\";
        }

        public string GetReg(string suppres)
        {

            string res = RegMask.Replace(@"%SUPPRES%", suppres);
            res = res.Replace(@"%install_dir%", getPath(getFolder(ExePath)));
            res = res.Replace(@"%install_exe%", getPath(ExePath));

            return res;
        }

        public void SetExePath(string path)
        {
            ExePath = path;
        }


    }
}
